package com.aaa.mks.service.impl;

import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.Result;
import com.aaa.mks.dao.CouponHistoryDao;
import com.aaa.mks.entity.CouponHistory;
import com.aaa.mks.service.CouponHistoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (CouponHistory)表服务实现类
 *
 * @author makejava
 * @since 2020-11-21 14:22:02
 */
@Service("couponHistoryService")
public class CouponHistoryServiceImpl implements CouponHistoryService {
    @Resource
    private CouponHistoryDao couponHistoryDao;

    @Override
    public Result queryAllByParam(Map map) {
        return new Result(ReturnCode.SUCCESSS.getCode(), ReturnCode.SUCCESSS.getMsg(), couponHistoryDao.queryAllByParam(map));
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CouponHistory queryById(Long id) {
        return this.couponHistoryDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<CouponHistory> queryAllByLimit(int offset, int limit) {
        return this.couponHistoryDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param couponHistory 实例对象
     * @return 实例对象
     */
    @Override
    public CouponHistory insert(CouponHistory couponHistory) {
        this.couponHistoryDao.insert(couponHistory);
        return couponHistory;
    }

    /**
     * 修改数据
     *
     * @param couponHistory 实例对象
     * @return 实例对象
     */
    @Override
    public CouponHistory update(CouponHistory couponHistory) {
        this.couponHistoryDao.update(couponHistory);
        return this.queryById(couponHistory.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.couponHistoryDao.deleteById(id) > 0;
    }
}